package com.sharp.kernel.mybatis.repository;

import com.sharp.kernel.utils.ReflectionUtil;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.Resource;

/**
 * Title: BaseMybatisRepository
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2022/7/27 9:46
 */
@SuppressWarnings("unchecked")
@CacheConfig(cacheNames = "DB-CACHE", keyGenerator = "cacheKeyByParam")
public class BaseMybatisRepository<T, K> extends ExampleFactory<T> {

    protected Class<T> entityClass = (Class<T>) ReflectionUtil.getSuperClassGenericType(this.getClass(), 0);
    protected Class<K> mapperClass = (Class<K>) ReflectionUtil.getSuperClassGenericType(this.getClass(), 1);

    @Resource
    private WebApplicationContext webApplicationContext;

    protected K getDao() {
        return webApplicationContext.getBean(mapperClass);
    }
}
